package com.example.testdemo.wbfile;

import android.app.Activity;
import android.content.Intent;
import android.net.Uri;
import android.os.Bundle;
import android.support.annotation.Nullable;
import android.widget.TextView;

import java.io.File;
/**
 * Created by MrYan on 2018/8/9.
 * 打开外部文件的中介Activity
 * 将外部文件打开后，在此处组装数据，然后以保存文件的形式，传递给项目文件夹；
 */

public class OpenExternalFileActivity extends Activity {
    @Override
    protected void onCreate(@Nullable Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        TextView textView = new TextView(this);
        setContentView(textView);
        //获取
        Intent intent = getIntent();
        Uri uri = intent.getData();
        if (uri == null) {
//            startApp();
            return;
        }
        String ddd = intent.getDataString();
        String path = Uri.decode(uri.getEncodedPath());
        File file = new File(path);
        textView.setText(ddd + "\n\n" + path + "\n\n" + file.exists());
        if (file.exists()) {
//            FileBean fileBean = new FileBean();
//            fileBean.setName(file.getName());
//            fileBean.setFilePath(path);
//            gotoWorkChainFolderActivity(fileBean);
//            ToastUitl.show("文件正确", Toast.LENGTH_LONG);
        } else {
//            startApp();
//            ToastUitl.show("文件不存在", Toast.LENGTH_LONG);
        }

    }

//    private void gotoWorkChainFolderActivity(FileBean fileBean) {
//        Intent intent = new Intent(this, WorkChainFolderActivity.class);
//        intent.putExtra(MyConstants.SAVE_FILE, fileBean);
//        startActivityForResult(intent, 0x888);
//    }
//
//
//    /**
//     * 启动App
//     */
//    private void startApp() {
//        if (AppManager.getAppManager().size() == 0) {
//            startActivity(new Intent(this, WelcomeActivity.class));
//            finish();
//        } else {
//            //如果不为空，说明App已经启动，直接关闭当前页面即可
//            finish();
//        }
//    }


    @Override
    protected void onActivityResult(int requestCode, int resultCode, Intent data) {
        super.onActivityResult(requestCode, resultCode, data);
        if (requestCode == 0x888 && resultCode == Activity.RESULT_OK) {
//            startApp();
        }
    }
}
